import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from 'src/layout'

import systemRouter from './modules/system'
import userRouter from './modules/user'
import productRouter from './modules/product'
import orderRouter from './modules/order'
import operationRouter from './modules/operation'
import statisticsRouter from './modules/dataStatistics'
import marketRouter from './modules/appMarket'


export const constantRoutes = [
  {
    path: '/login',
    component: () => import('src/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('src/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [{
      path: 'index',
      name: 'Home',
      component: () => import('src/views/Home.vue'),
      meta: {title: '首页', icon: 'dashboard',affix: true}
    }]
  },
  systemRouter,
  userRouter,
  productRouter,
  orderRouter,
  operationRouter,
  statisticsRouter,
  marketRouter,
  {
    path: "*",
    redirect: "/404",
  }
];

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})

const router = createRouter();


// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
